package is.server.controller.session.local;

import is.common.interfaces.Command;
import is.common.syntax.CommandQualifier;
import is.server.controller.session.local.command.*;

import java.util.Arrays;

/**
 * Factory returns commands according to user input.
 *
 * @author aspr0
 *         Date: 07.04.12
 *         Time: 12:05
 */
public class CommandFactory
{
    public static Command newInstance(String[] request)
    {
        String requestQualifier = request[0];
        String[] params = Arrays.copyOfRange(request, 1, request.length);


        if (CommandQualifier.QUIT.equals(requestQualifier))
        {
            return new QuitCommand();
        }
        else if (CommandQualifier.OPEN.equals(requestQualifier))
        {
            return new OpenCommand(params);
        }
        else if (CommandQualifier.CONCAT.equals(requestQualifier))
        {
            return new ConcatCommand(params);
        }
        else if (CommandQualifier.LIST.equals(requestQualifier))
        {
            return new ListCommand(request);
        }
        else
        {
            return new UnknownCommand();
        }
    }

}
